﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Web;

namespace PublicLib.Lib.Zip
{
    public class ZipStream
    {
        public byte[] Zip(byte[] buffer)
        {
            return Zip(new MemoryStream(buffer));
        }
        public byte[] Zip(Stream buffer)
        {
            Stream stream = new DeflateStream(buffer, CompressionMode.Compress);
            byte[] res = new byte[stream.Length];
            stream.Write(res, 0, (int)stream.Length);
            return res;
        }

        public byte[] UnZip(byte[] buffer)
        {
            return Zip(new MemoryStream(buffer));
        }
        public byte[] UnZip(Stream buffer)
        {
            Stream stream = new DeflateStream(buffer, CompressionMode.Decompress);
            byte[] res = new byte[stream.Length];
            stream.Write(res, 0, (int)stream.Length);
            return res;
        }
    }
}